package com.lihan.GetSeatInLib.Controllers;

import java.util.HashSet;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.lihan.GetSeatInLib.Domain.FloorModel;
import com.lihan.GetSeatInLib.Domain.StandReturnMessage;
import com.lihan.GetSeatInLib.Service.FloorService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = "楼层操作API")
@RestController
@RequestMapping("/Floor")
public class FloorController {
	
	@Autowired
	private FloorService floorService;
	
	@ApiOperation("获取楼层的所有信息")
	@GetMapping("/GetAllFloor")
	public Set<FloorModel> GetAllFloorData(){
		return floorService.getAllFloor();
	}
	
	@ApiOperation("获取指定ID的楼层数据")
	@GetMapping("/GetFloorById")
	public StandReturnMessage<FloorModel> GetFloorById(Integer ID) {
		FloorModel model = floorService.getFloorById(ID);
		if(model!=null)
			return new StandReturnMessage<FloorModel>(200,model,1);
		else
			return new StandReturnMessage<FloorModel>(400,null,0);
	}
	
	/**
	 * 
	 * @Title: CreateNewFloor
	 * @Description: 创建一个新的楼层
	 * @param @param alias 别名
	 * @param @param index 层数
	 * @param @return 参数
	 * @return StandReturnMessage<Boolean> 返回类型
	 * @throws
	 */
	@ApiOperation("新增一个楼层信息")
	@PostMapping("/CreateFloor")
	public StandReturnMessage<Boolean> CreateNewFloor(String alias,int index){
		//先掉一遍查询所有，先让redis有缓存，再在create方法中删除该缓存
		floorService.getAllFloor();
		FloorModel floor = new FloorModel();
		floor.setAlias(alias);
		floor.setTheIndex(index);
		boolean result = floorService.CreateNewFloor(floor);
		if(result)
			return new StandReturnMessage<Boolean>(200, result, 1);
		else
			return new StandReturnMessage<Boolean>(400, result, 0);
	}

	public StandReturnMessage<Boolean> DeleteNewFloor(Integer ID){
		Boolean result = floorService.DeleteFloorById(ID);
		return new StandReturnMessage<Boolean>(200, result, 1);
	}
}
